import WatchNumber from "@/utils/WatchNumber";
import GradualNumber from "@/utils/GradualNumber";
import WatchGradualNumber from "@/utils/WatchGradualNumber";
import Mota, { MotaInterface } from "@/mota";

export default class SpeedUtils implements MotaInterface {
    public Mota: Mota;

    public length = new WatchNumber(4);

    public pos = new WatchNumber(0);

    public speed = new WatchNumber(10);

    public progress = new WatchNumber((p, s) => Math.floor(p.Value / s.Value), this.pos, this.speed);

    public count = new WatchNumber((l, s) => l.Value * s.Value, this.length, this.speed);

    public speed2 = new WatchNumber(2);

    public count2 = new WatchNumber((l, s) => l.Value * s.Value, this.length, this.speed2);

    public ZIndex: number = -1;

    constructor(mota: Mota) {
        this.Mota = mota;
    }

    public MakeChanger(num: number): WatchGradualNumber {
        return new WatchGradualNumber(num, this.count2, {
            Value: GradualNumber.MakeChanger("line"),
        });
    };

    public Trigger(): void {
        if (++this.pos.Value >= this.count.Value) {
            this.pos.Value = 0;
        }
    }
}